<template>
	<div>
		<el-row :gutter="10">
			<el-col :span="24">
				<el-card shadow="never" class="card">
					<div id="charts_one" style="width:100%;min-height:80vh">
            <Search size='small' :searchVisible="searchVisible" :searchData.sync="searchData"  :searchForm="searchForm" @refresh_list="index"></Search>
						<div class="btn-group" style="margin-bottom:11px;">
                           <div>
<!--							   <el-button type="success"  size="mini" icon="el-icon-plus"  @click="add(ids)" v-if="checkPermission('/app/Material/add.html')" >{{$t('action.add')}}</el-button>   -->
<!--                               <el-button type="primary" :disabled="single" size="mini" icon="el-icon-edit"  @click="update(ids)" v-if="checkPermission('/app/Material/update.html')" >{{$t('action.update')}}</el-button>  -->
<!--							   <el-button type="danger" :disabled="multiple" size="mini" icon="el-icon-delete"  @click="del(ids)" v-if="checkPermission('/app/Material/delete.html')" >{{$t('action.delete')}}</el-button>     -->
<!--                               <el-button type="info" :disabled="single" size="mini" icon="el-icon-view"  @click="detail(ids)" v-if="checkPermission('/app/Material/detail.html')" >{{$t('action.detail')}}</el-button>  -->
                           </div>
                           <table-tool :searchVisible.sync="searchVisible"  :fieldList="fieldList" @refresh_list="index" :searchTool="true"></table-tool>
						</div>
					    <el-table :row-class-name="rowClass" @selection-change="selection"  @row-click="handleRowClick"  row-key="id"  :header-cell-style="{ background: '#eef1f6', color: '#606266' }" v-loading="loading"  ref="multipleTable" border class="eltable" :data="list"  style="width: 100%">		   
						    <el-table-column align="center" type="selection" width="42"></el-table-column>
							<el-table-column align="center" type='' v-if="fieldList[0].checked" property="id" label="ID" show-overflow-tooltip width="70">
							</el-table-column>
							<el-table-column align="center"  v-if="fieldList[1].checked" property="id" :label="$t('field.MoldMaintenancel_Id')" show-overflow-tooltip width="" >
							</el-table-column>
							<el-table-column align="center"  v-if="fieldList[2].checked" property="billNo" :label="$t('field.MoldMaintenancel_billNo')" show-overflow-tooltip width="" >
							</el-table-column>
							<el-table-column align="center"  v-if="fieldList[3].checked" property="materialNo" :label="$t('field.MoldMaintenancel_materialNo')" show-overflow-tooltip width="" >
							</el-table-column>
							<el-table-column align="center"  v-if="fieldList[4].checked" property="materialName" :label="$t('field.MoldMaintenancel_materialName')" show-overflow-tooltip width="" >
							</el-table-column>
							<el-table-column align="center"  v-if="fieldList[5].checked" property="createTime" :label="$t('field.MoldMaintenancel_createTime')" show-overflow-tooltip width="" >
							</el-table-column>
							<el-table-column align="center"  v-if="fieldList[6].checked" property="createUserName" :label="$t('field.MoldMaintenancel_createUserName')" show-overflow-tooltip width="" >
							</el-table-column>
							<el-table-column align="center"  v-if="fieldList[7].checked" property="locationNo" :label="$t('field.MoldMaintenancel_locationNo')" show-overflow-tooltip width="" >
							</el-table-column>
							<el-table-column align="center"  v-if="fieldList[8].checked" property="locationName" :label="$t('field.MoldMaintenancel_locationName')" show-overflow-tooltip width="" >
							</el-table-column>
							<el-table-column align="center"  v-if="fieldList[9].checked" property="inspectNo" :label="$t('field.MoldMaintenancel_inspectNo')" show-overflow-tooltip width="" >
							</el-table-column>
							<el-table-column align="center"  v-if="fieldList[10].checked" property="category" :label="$t('field.MoldMaintenancel_category')" show-overflow-tooltip width="" >
                <template slot-scope="scope">
                  <el-tag type="warning" v-if="scope.row.category == '1'" size="mini" effect="dark">大修</el-tag>
                  <el-tag type="warning" v-if="scope.row.category == '0'" size="mini" effect="dark">小修</el-tag>
                </template>
							</el-table-column>
                <el-table-column align="center"  v-if="fieldList[11].checked" property="status" :label="$t('field.MoldMaintenancel_status')" show-overflow-tooltip width="" >
                  <template slot-scope="scope">
                    <el-tag type="warning" v-if="scope.row.status == '1'" size="mini" effect="dark">未完成</el-tag>
                    <el-tag type="warning" v-if="scope.row.status == '2'" size="mini" effect="dark">已完成</el-tag>
                  </template>
                </el-table-column>
							<el-table-column align="center"  v-if="fieldList[12].checked" property="repairName" :label="$t('field.MoldMaintenancel_repairName')" show-overflow-tooltip width="" >
							</el-table-column>
							<el-table-column align="center"  v-if="fieldList[13].checked" property="repairStartTime" :label="$t('field.MoldMaintenancel_repairStartTime')" show-overflow-tooltip width="" >
							</el-table-column>
							<el-table-column align="center"  v-if="fieldList[14].checked" property="repairEndTime" :label="$t('field.MoldMaintenancel_repairEndTime')" show-overflow-tooltip width="" >
							</el-table-column>

                <el-table-column align="center"  v-if="fieldList[15].checked" property="inStockNo" :label="$t('field.MoldMaintenancel_inStockNo')" show-overflow-tooltip width="" >
                </el-table-column>
                <el-table-column align="center"  v-if="fieldList[16].checked" property="remark" :label="$t('field.MoldMaintenancel_remark')" show-overflow-tooltip width="" >
                </el-table-column>
                <el-table-column align="center"  v-if="fieldList[17].checked" property="moldId" :label="$t('field.MoldMaintenancel_moldId')" show-overflow-tooltip width="" >
                </el-table-column>

                <el-table-column align="center"  v-if="fieldList[18].checked" property="stockNo" :label="$t('field.MoldMaintenancel_stockNo')" show-overflow-tooltip width="" >
                </el-table-column>
                <el-table-column align="center"  v-if="fieldList[19].checked" property="stockName" :label="$t('field.MoldMaintenancel_stockName')" show-overflow-tooltip width="" >
                </el-table-column>
						</el-table>
						<Page :total="page_data.total" :page.sync="page_data.page" :limit.sync="page_data.limit" @pagination="index" />
					</div>
				</el-card>
			</el-col>
		</el-row>

	</div>
</template>
<script>
	import {
	    index, 
	    updateExt, 
	    getUpdateInfo,
	    del,
	} from '@/api/app/moldmaintenance'
	import Search from '@/components/common/Search.vue'
	import Page from '@/components/common/Page.vue'
	import TableTool from '@/components/common/TableTool.vue'
	import { confirm,param2Obj } from '@/utils/common'

	export default {
		name:'moldmaintenance',
		components: {
			Search,
			Page,
			TableTool
		},
		data(){
			return {
				dialog: {
				},
        fieldList: [
          { lable: 'ID', checked: false },
          { lable: this.$t('field.MoldMaintenancel_Id'), checked: false },
          { lable: this.$t('field.MoldMaintenancel_billNo'), checked: true },
          { lable: this.$t('field.MoldMaintenancel_materialNo'), checked: true },
          { lable: this.$t('field.MoldMaintenancel_materialName'), checked: true },
          { lable: this.$t('field.MoldMaintenancel_createTime'), checked: true },
          { lable: this.$t('field.MoldMaintenancel_createUserName'), checked: true },
          { lable: this.$t('field.MoldMaintenancel_locationNo'), checked: false },
          { lable: this.$t('field.MoldMaintenancel_locationName'), checked: true },
          { lable: this.$t('field.MoldMaintenancel_inspectNo'), checked: true },
          { lable: this.$t('field.MoldMaintenancel_category'), checked: true },
          { lable: this.$t('field.MoldMaintenancel_status'), checked: true },
          { lable: this.$t('field.MoldMaintenancel_repairName'), checked: true },
          { lable: this.$t('field.MoldMaintenancel_repairStartTime'), checked: true },
          { lable: this.$t('field.MoldMaintenancel_repairEndTime'), checked: true },
          { lable: this.$t('field.MoldMaintenancel_inStockNo'), checked: true },
          { lable: this.$t('field.MoldMaintenancel_remark'), checked: true },
          { lable: this.$t('field.MoldMaintenancel_moldId'), checked: true },
          { lable: this.$t('field.MoldMaintenancel_stockNo'), checked: true },
          { lable: this.$t('field.MoldMaintenancel_stockName'), checked: true }
        ],
				ids: [],
				selectRows:[],
				selectTotal:0,
				single:true,
				multiple:true,
				list: [],
				small_tables:{},
	            addInfo:{},
	            updateInfo:{},
	            detailInfo:{},
				loading: false,
				page_data: {
					limit: 20,
					page: 1,
					total:20,
				},
				searchVisible:true,
				searchForm:[],
				searchData:{},
			}
		},
		methods: {
			index(){
				let param = {limit:this.page_data.limit,page:this.page_data.page}
				Object.assign(param, this.searchData,param2Obj(this.$route.fullPath))
				this.loading = true
				index(param).then(res => {
					this.list = res.data.data
					this.small_tables=res.sql_field_data
					this.page_data.total = res.data.total
					this.loading = false
					if(this.page_data.page == 1){
						this.searchForm = [
              {type:'Input',label:this.$t('field.MoldMaintenancel_billNo'),prop:'billNo',width:'150px'},
              {type:'Input',label:this.$t('field.MoldMaintenancel_inspectNo'),prop:'inspectNo',width:'150px'},
              {type:'Input',label:this.$t('field.MoldMaintenancel_inStockNo'),prop:'inStockNo',width:'150px'},
              {type:'Input',label:this.$t('field.MoldMaintenancel_materialNo'),prop:'materialNo',width:'150px'},
              {type:'Input',label:this.$t('field.MoldMaintenancel_materialName'),prop:'materialName',width:'150px'},
              {type:'Input',label:this.$t('field.MoldMaintenancel_stockNo'),prop:'stockNo',width:'150px'},
              {type:'Input',label:this.$t('field.MoldMaintenancel_stockName'),prop:'stockName',width:'150px'},
              {type:'Input',label:this.$t('field.MoldMaintenancel_createUserName'),prop:'createUserName',width:'150px'},
              {type:'datetime',label:this.$t('field.MoldMaintenancel_createTime'),prop:'createTime',width:'150px'},
              {type:'Input',label:this.$t('field.MoldMaintenancel_repairName'),prop:'repairName',width:'150px'},
              {type:'datetime',label:this.$t('field.MoldMaintenancel_repairStartTime'),prop:'repairStartTime',width:'150px'},
              {type:'datetime',label:this.$t('field.MoldMaintenancel_repairEndTime'),prop:'repairEndTime',width:'150px'},
						]
					}
				})
			},
			updateExt(row,field){
				if(row.id){
					updateExt({id:row.id,[field]:row[field]}).then(res => {
						this.$message({message: this.$t('system.success'), type: 'success'})
					})
				}
			},
			update(row){
				let id = row.id ? row.id : this.ids.join(',')
				getUpdateInfo({id:id}).then(res => {
					if(res.status == 200){
						this.dialog.updateDialogStatus = true
						this.updateInfo = res.data
					}
				})
			},
			del(row){
				confirm({content:this.$t('system.confirmOperation')}).then(() => {
					let ids = row.id ? row.id : this.ids.join(',')
					del({id:ids}).then(res => {
						this.$message({message: this.$t(res.msg), type: 'success'})
						this.index()
					})
				}).catch(() => {})
			},
			detail(row){
				this.dialog.detailDialogStatus = true
				this.detailInfo = {id:row.id ? row.id : this.ids.join(',')}
			},
			selection(selection) {
			    this.selectRows=selection
			    this.selectTotal=selection.length
				this.ids = selection.map(item => item.id)
				this.single = selection.length != 1
				this.multiple = !selection.length
			},
			handleRowClick(row, rowIndex,event){
				if(event.target.className !== 'el-input__inner'){
					this.$refs.multipleTable.toggleRowSelection(row)
				}
			},
			rowClass ({ row, rowIndex }) {
				for(let i=0;i<this.ids.length;i++) {
					if (row.id === this.ids[i]) {
						return 'rowLight'
					}
				}
			},
		},	
		mounted(){
			this.index()
		}
	}
</script>
<style  lang="scss">
@import '@/assets/scss/common.scss'
</style>